const mongoose = require('mongoose')
const env = require('../config.js')

//连接数据库
mongoose.connect(env.mLap,{ useNewUrlParser: true })

const Schema = mongoose.Schema

let topicSchema = new Schema({
    title: {
        type: String,
        required: true
    },
    topic: {
        type: String,
        required: true
    },
    user_id: {
        type: Schema.Types.ObjectId,
        ref: 'User'
    },
    created_time: {
        type: Date,
        default: Date.now   
    },
    last_modified_time: {
        type: Date,
        default: Date.now
    },
    
})
//Date.now(),不要这样写,因为会即刻调用, 这里直接给一个方法: Date.now
//当你去 new model 时,没传值,mongoose就高用这个方法,返回现在的时间
//而你写Date.now() ,时,会把创建时的时间,做为dfault的默认值,而不再是一个方法了.是/
//一个固定值了

module.exports = mongoose.model('Topic', topicSchema)
